iT邦幫忙

2024 iThome 鐵人賽

DAY 21
0
Software Development

LSTM結合Yolo v8對於多隻斑馬魚行為分析系列 第 21

day 21lstm預測晶圓良率結合yolo淘汰不良的晶圓

  • 分享至 

  • xImage
  •  

今天是第二十一天我們可以寫一個lstm去預測晶圓的良率並且結合yolo去辨識淘汰不良的晶圓,以下是程式碼
可以分成兩個主要步驟來完成:

  1. LSTM 模型: 用來預測晶片的良率(即預測晶圓是否會生產出良好的晶片)。
  2. YOLO 模型: 用來辨識晶圓表面或其他特徵來判斷是否有缺陷,並根據此結果淘汰不良的晶圓。

步驟 1: LSTM 模型來預測晶片良率

這裡假設我有一組歷史數據,包括製造過程中的各項參數(如溫度、壓力、時間等)以及最終的良率。

1.1 準備數據

import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import LSTM, Dense

# 假設我們有一個包含製造過程數據的CSV文件
data = pd.read_csv('chip_yield_data.csv')

# 選擇特徵與標籤
features = data[['temperature', 'pressure', 'time', 'other_params']].values
labels = data['yield'].values

# 標準化數據
scaler = MinMaxScaler()
features_scaled = scaler.fit_transform(features)

# 重塑數據為LSTM需要的形狀 [samples, time_steps, features]
time_steps = 10
X = []
y = []

for i in range(time_steps, len(features_scaled)):
    X.append(features_scaled[i-time_steps:i])
    y.append(labels[i])

X, y = np.array(X), np.array(y)

# 分割數據為訓練集和測試集
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

1.2 建立並訓練LSTM模型

# 建立LSTM模型
model = Sequential()
model.add(LSTM(units=50, return_sequences=True, input_shape=(X_train.shape[1], X_train.shape[2])))
model.add(LSTM(units=50))
model.add(Dense(units=1, activation='sigmoid'))  # 用於預測良率,範圍0-1

# 編譯模型
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])

# 訓練模型
model.fit(X_train, y_train, epochs=20, batch_size=32, validation_data=(X_test, y_test))

步驟 2: YOLO 模型來辨識不良晶圓

這裡假設我有一個預訓練的YOLO模型,能夠辨識晶圓上的缺陷。

2.1 加載YOLO模型

import cv2
import numpy as np

# 假設我們有預訓練好的YOLOv8模型
# 從weights檔案中載入模型
net = cv2.dnn.readNet('yolov8.weights', 'yolov8.cfg')
layer_names = net.getLayerNames()
output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]

def detect_defects(image_path):
    image = cv2.imread(image_path)
    height, width = image.shape[:2]

    # 準備YOLO輸入
    blob = cv2.dnn.blobFromImage(image, 0.00392, (416, 416), (0, 0, 0), True, crop=False)
    net.setInput(blob)
    outputs = net.forward(output_layers)

    # 處理YOLO輸出
    for output in outputs:
        for detection in output:
            scores = detection[5:]
            class_id = np.argmax(scores)
            confidence = scores[class_id]
            if confidence > 0.5:  # 設定置信度閾值
                center_x = int(detection[0] * width)
                center_y = int(detection[1] * height)
                w = int(detection[2] * width)
                h = int(detection[3] * height)
                x = int(center_x - w / 2)
                y = int(center_y - h / 2)

                # 框選缺陷部分
                cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)
                cv2.putText(image, "Defect", (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)

    return image

2.2 結合LSTM預測與YOLO辨識

假設LSTM模型預測的良率低於某個閾值,則使用YOLO進行進一步檢查。

def evaluate_chip(image_path, process_data):
    # 使用LSTM模型預測良率
    process_data_scaled = scaler.transform([process_data])
    process_data_reshaped = np.reshape(process_data_scaled, (1, time_steps, len(process_data)))
    yield_prediction = model.predict(process_data_reshaped)[0][0]

    if yield_prediction < 0.8:  # 假設良率閾值為80%
        # 使用YOLO辨識晶圓上的缺陷
        defect_image = detect_defects(image_path)
        cv2.imshow('Detected Defects', defect_image)
        cv2.waitKey(0)
        cv2.destroyAllWindows()
        return "Defects Detected"

    return "Yield is acceptable"

系統整合

  • LSTM模型預測整個製程的晶圓良率。
  • 如果預測良率低於某個閾值,則進一步使用YOLO模型來檢查晶圓表面,並標記出缺陷的位置。
  • 如果檢測到缺陷,系統自動淘汰該晶圓,並可能進行進一步的分析或處理。

這樣的系統可以大大提高晶片生產的效率和質量控制,透過LSTM預測來篩選可能有問題的晶圓,並通過YOLO進行詳細的檢查和淘汰。


上一篇
Lstm結合yolo分析斑馬魚陰影是否造成實驗誤差
下一篇
day 22 yolo結合lstm去評斷空氣品質系統
系列文
LSTM結合Yolo v8對於多隻斑馬魚行為分析29
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言